<template>
<div>
  <el-row style="margin-left: -1300px">
    <el-col :span="16" :offset="5">
<!--      <el-input type="text" placeholder="请输入姓名的关键字进行查找" style="width: 60%" v-model="finds.name">-->
<!--        <el-button slot="append" icon="el-icon-search" @click="finduser()"></el-button>-->
<!--      </el-input>-->
      <el-button type="primary" plain @click="dialogFormVisible1=true">添加</el-button>
    </el-col>
  </el-row>
  <el-dialog title="信息" :visible.sync="dialogFormVisible1">
    <el-form>
      <el-form-item label="采购员">
        <el-select v-model="applydate.uid" placeholder="请选择" >
          <el-option v-for="item in user" :label="item.name" :key="item.uid" :value="item.uid"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="图书">
        <el-select v-model="applydate.book" placeholder="请选择" >
          <el-option v-for="item in bookfind" :label="item.name" :key="item.id" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预计商品数量" >
        <el-input v-model="applydate.quantity" style="width: 260px" ></el-input>
      </el-form-item>

      <el-form-item label="采购总价" >
        <el-input v-model="applydate.price" style="width: 260px" ></el-input>
      </el-form-item>
      <el-form-item label="预计商品采购总价价" >
        <el-input v-model="applydate.budget" style="width: 260px" ></el-input>
      </el-form-item>

      <el-form-item label="实际采购数量">
        <el-input v-model="applydate.realityamount" style="width: 260px" ></el-input>
      </el-form-item>
      <el-form-item label="实际采购总价">
        <el-input v-model="applydate.realityprice" style="width: 260px" ></el-input>
      </el-form-item>

      <el-form-item label="入库数量">
        <el-input v-model="applydate.amount" style="width: 260px" ></el-input>
      </el-form-item>

      <el-form-item label="备注">
        <el-input type="textarea" v-model="applydate.remark"></el-input>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="adds()">确 定</el-button>
    </div>
  </el-dialog>
<br>
  <el-table
    :data="tableData"
    stripe
    style="width: 100%">
    <el-table-column
      prop="id"
      label="编号"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="采购员"
      width="180">
    </el-table-column>
    <el-table-column
      prop="bookname"
      label="图书"
      width="180">
    </el-table-column>
    <el-table-column
      prop="quantity"
      label="预计商品采购数"
      width="180">
    </el-table-column>
    <el-table-column
      prop="price"
      label="采购总价"
      width="180">
    </el-table-column>
    <el-table-column label="状态">
      <template slot-scope="scope">
        <span v-if="scope.row.state == 0">未审核</span>
        <span v-if="scope.row.state == 1">已审核</span>
      </template>
    </el-table-column>
    <el-table-column
      prop="budget"
      label="预计总价"
      width="180">
    </el-table-column>
    <el-table-column
      prop="realityamount"
      label="实际采购数"
      width="180">
    </el-table-column>
    <el-table-column
      prop="realityprice"
      label="实际采购价格"
      width="180">
    </el-table-column>
    <el-table-column
      prop="date" :formatter="dateFormat"
      label="采购单创建时间"
      width="180">
    </el-table-column>
    <el-table-column
      prop="amount"
      label="入库数量"
      width="180">
    </el-table-column>
    <el-table-column
      prop="remark"
      label="备注"
      width="180">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="dialogFormVisible=true;updapply=scope.row" type="primary"
                   icon="el-icon-edit" size="small">查看</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    small
    @size-change="pageSize"
    layout="total,prev, pager, next"
    :page-size="pageSize"
    :total="total" @current-change="page">
  </el-pagination>
  <el-dialog title="信息" :visible.sync="dialogFormVisible">
    <el-form>
      <el-form-item label="采购员">
        <el-select v-model="updapply.uid" placeholder="请选择" disabled="">
          <el-option v-for="item in user" :label="item.name" :key="item.uid" :value="item.uid"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="图书">
        <el-select v-model="updapply.book" placeholder="请选择" disabled="">
          <el-option v-for="item in bookfind" :label="item.name" :key="item.id" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预计商品数量" >
        <el-input v-model="updapply.quantity" style="width: 260px" disabled=""></el-input>
      </el-form-item>

      <el-form-item label="采购总价" >
        <el-input v-model="updapply.price" style="width: 260px" disabled=""></el-input>
      </el-form-item>
      <el-form-item label="预计商品采购总价" >
        <el-input v-model="updapply.budget" style="width: 260px" disabled=""></el-input>
      </el-form-item>
      <el-form-item label="审核状态....">
        <template>
          <el-select v-model="updapply.state" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-form-item>

      <el-form-item label="实际采购数量">
        <el-input v-model="updapply.realityamount" style="width: 260px" disabled=""></el-input>
      </el-form-item>
      <el-form-item label="实际采购总价">
        <el-input v-model="updapply.realityprice" style="width: 260px" disabled=""></el-input>
      </el-form-item>

      <el-form-item label="实际采购时间">
        <el-date-picker
          v-model="updapply.date"
          type="datetime"
          placeholder="选择日期时间" disabled="">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="实际采购总价">
        <el-input v-model="updapply.amount" style="width: 260px" disabled=""></el-input>
      </el-form-item>

      <el-form-item label="备注">
        <el-input type="textarea" v-model="updapply.remark"></el-input>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="upd()">确 定</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
export default {
  name: "Apply",
  data(){
    return{
      total: 0,
      pageSize: 6,
      dialogFormVisible1:false,
      tableData: [],
      dialogFormVisible:false,
      applydate:{
        uid:"",book:"",quantity:"",price:"",budget:"",
        realityamount:"",realityprice:"",realitotal:"",amount:"",remark:""
      },
      user: [],
      updapply:{},
      bookfind:[],
      options: [{
        value: '0',
        label: '未审核'
      }, {
        value: '1',
        label: '审核通过'
      }],
      finds:{name:""}
    }
  },
  created() {
    this.find()
    this.userfind()
    this.findbook()
  },
  methods:{
    find(){
      this.$http.post("backservice/applydate/findpage?pageNum=0&pageSize=" + this.pageSize).then(response => {
        console.log(response.userList)
        this.tableData = response.userList
        this.total = response.TotalNum
      })
    },
    page(currentPage) {
      this.$http.post('backservice/applydate/findpage?&pageNum=' + (currentPage-1) + '&pageSize=' + this.pageSize)
        .then(response => {
          this.tableData = response.userList
        })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    userfind(){
      this.$http.post('backservice/user/finduser1').then(data=>{
        this.user=data
      })
    },
    add(){
      this.dialogFormVisible = false
      this.$http.post('backservice/apply/add',this.apply).then(data=>{
        if (data>0){
          this.find()
          alert("添加成功")
        }else{
          alert("添加失败")
        }
      })
    },
    dateFormat(row, column, cellValue, index) {
      const daterc = row[column.property]
      if (daterc != null) {
        var date = new Date(daterc);
        var year = date.getFullYear();
        /* 在日期格式中，月份是从0开始，11结束，因此要加0
         * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
         * */
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        // 拼接
        return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
      }
    },
    findbook(){
      this.$http.post('backservice/book/find1').then(data=>{
         this.bookfind=data
      })

    },
    upd(){
      this.dialogFormVisible=false
      this.$http.post('backservice/applydate/upd',this.updapply).then(data=>{
        if (data>0){
          this.find()
          alert("审核成功")
        }else {
          alert("审核失败")
        }
      })
    },
    finduser(){
      let name=this.finds.name
      if (name!=null){
        this.$http.post('backservice/applydate/select1',this.finds).then(data=>{
          console.log(data)
          this.tableData=data
        })
      }else {
        this.find()
      }
    },
    adds(){
      this.dialogFormVisible1=false
     this.$http.post('backservice/applydate/add',this.applydate).then(data=>{
       if (data>0){
         this.find()
         alert("添加成功")
       }else {
         alert("添加失败")
       }
     })

    }

  }
}
</script>

<style scoped>

</style>
